begintownscript;

variables;
short creature_count = 0;
short choice = 0;
short pc_counter = 0;
short lead_char = 0;
short pctalker = 0;

body;

beginstate 0; //INIT_STATE
	set_crime_tolerance(2);

	change_outdoor_location(0,0,23,16);

	if(get_flag(10,7) == 2)
		activate_hidden_group(1);

	relocate_character(0,5,14);
	relocate_character(1,5,15);
	relocate_character(2,5,16);
	relocate_character(3,5,17);
	set_character_pose(1000,14);
	force_instant_terrain_redraw();

	set_state_continue(10);

break;


beginstate 1; //EXIT_STATE - THE END!!!

break;


beginstate 2; //START_STATE
	pc_counter = 0;
	while(char_ok(pc_counter) == 0) {
		pc_counter = pc_counter + 1;
		}
	lead_char = pc_counter;


break;



beginstate 10; //Teh cutscene!

	pause(15);
	reset_dialog();
	if(get_flag(10,7) == 2) {
		add_dialog_str(0,"...you awake, groggy, soaked, and aching. You're on dry land, which is a good start. You have no idea where you are, which is bad.",0);
		add_dialog_str(1,"Then, you notice Mitch standing over you. Definitely a good sign. You think you can see a man in a green cloak off behind Mitch, but you could be wrong. In any case, you look again and he's gone.",0);
		add_dialog_str(2,"Before you can say anything, Mitch speaks.",0);
		run_dialog(1);

		force_view_center(7,16);
		erase_char(7);
		force_instant_terrain_redraw();
		pause(5);
		text_bubble_on_char(6,"Good, you're awake.");
		force_instant_terrain_redraw();
		pause(15);
		erase_text_bubbles();
		text_bubble_on_char(6,"I was getting worried");
		force_instant_terrain_redraw();
		pause(15);
		erase_text_bubbles();
		text_bubble_on_char(6,"that you wouldn't wake up.");
		force_instant_terrain_redraw();
		pause(15);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(5);
		set_character_facing(6,6);
		text_bubble_on_char(6,"But, now that I know you're alive,");
		force_instant_terrain_redraw();
		pause(15);
		erase_text_bubbles();
		text_bubble_on_char(6,"I can finally get going.");
		force_instant_terrain_redraw();
		pause(18);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		reset_dialog();
		erase_char(6);
		force_instant_terrain_redraw();
		if(get_flag(0,5) == 1)
			add_dialog_str(0,"He walks away, not even deigning to help you up off the ground.",0);
		else
			add_dialog_str(0,"He helps you up off the ground, and then he walks (or rather, limps) away slowly.",0);
		add_dialog_str(1,"As he leaves, you hear him call back _Good luck, friends!_ shortly followed by _Wait for me, Brother!_",0);
		if(get_flag(0,5) == 1)
			add_dialog_str(2,"You carefully try to stand up, and find that your bones are mostly intact. At the very least, it seems that you'll be able to walk.",0);
		run_dialog(1);
		set_character_pose(1000,0);
		set_character_facing(1000,6);
		force_view_center(5,14);
		force_instant_terrain_Redraw();
	}
	else {
		add_dialog_str(0,"...you awake, groggy, soaked, and aching. You're on dry land, which is a good start. You have no idea where you are, which is bad.",0);
		add_dialog_str(1,"Taking a brief look around you, you don't see any people. Well, you could've sworn you saw a green-cloaked man standing a short way away from you, but he's gone by the time you get a second look.",0);
		add_dialog_str(2,"You carefully try to stand up, and find that your bones are mostly intact. At the very least, it seems that you'll be able to walk.",0);
		run_dialog(1);
		set_character_pose(1000,0);
		set_character_facing(1000,2);
		force_view_center(5,14);
		erase_char(7);
		force_instant_terrain_Redraw();
	}

	pause(5);
	reset_dialog();
	add_dialog_str(0,"Looking around in more detail, you're starting to get a good idea of where you washed up.",0);
	if(get_flag(20,1) == 1)
		add_dialog_str(1,"You've been here before, actually. This is the deserted fishing camp you found on the other side of the lake from Hektos. Unsurprisingly, there's still nobody here.",0);
	else
		add_dialog_str(1,"You can see a well-stoked fire, along with a decidedly ramshackle building. Looking out across the lake, you see... Hektos! So you're not as lost as you thought!",0);
	run_dialog(1);

break;



beginstate 15; //the fire
	
	if(get_flag(8,0) == 0) {
		message_dialog("Hm... this fire has been stoked recently. And it looks like somebody left part of a meal cooking on it.","");
		set_flag(8,0,1);
		}

break;

beginstate 16; //the fire, specobj

	message_dialog("You lean in to search the fire, and you burn yourselves.","Well, that was stupid.");
	damage_near_loc(15,13,10,1,1);

break;

beginstate 20; //woodpiles, specobj

	message_dialog("Most of the firewood here is just a bit moldy. It looks like it's been here for a long time.","It's anyone's guess as to who put it here.");

break;

beginstate 25; // road construction dialog
	
	if(get_flag(8,1) == 0) {
		message_dialog("It looks like this construction of this road was simply abandoned. Maybe something important was supposed to be built down here.","Either way, this road should lead you back to Hektos.");
		set_flag(8,1,1);
		}

break;

beginstate 30; // teh shack! dialog
	
	if(get_flag(8,2) == 0) {
		message_dialog("The door of this shack flaps back and forth in the wind a bit. It doesn't even have a lock, though it's not like the building's contents warrant one.","The only items of interest are the fish on the table, because they smell like they're still vaguely edible.");
		set_flag(8,2,1);
		}

break;

beginstate 35; //easter egg hint
	
	if(get_flag(8,3) == 0) {
		print_str("You see something shiny beneath the bush at the edge of the trees.");
		set_flag(8,3,1);
		}

break;

beginstate 36; //easter egg

	if(get_flag(8,3) == 1) {
		reset_dialog();

		add_dialog_str(0,"This is very, very odd. Beneath this bush, you find a large and rather impressively decorated egg. It sparkles in the sunlight. Unless you're mistaken, it's been engraved.",0);
		add_dialog_str(1,"Do you examine it?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No.");

		choice = run_dialog(1);

		if(choice == 1) {
			reset_dialog();
			add_dialog_str(0,"Picking up the egg and looking closer, you can read the fine engraving:",0);
			add_dialog_str(1,"_To a shadow of his former self, and the victim of the transformation. May your souls find peace one day. - A.S. and E.M._",15);
			add_dialog_str(2,"Before you can read any further, the egg cracks open in your hands, revealing a very clich snow white dove. It flies away, and the halves of the egg shatter on the ground.",0);
			run_dialog(1);

			set_flag(8,3,2);
			}
		else {
			reset_dialog();
			add_dialog_str(0,"You tuck the egg back under the bush.",0);
			run_dialog(1);
			}
		}

break;

beginstate 40; //THE END!!!

	reset_dialog();
	add_dialog_str(0,"Still a little weak on your feet, you leave the abandoned camp, hellbent on getting some sort of reward for your work.",0);
	run_dialog(1);

	force_view_center(0,0);
	force_instant_terrain_redraw();

	reset_dialog();
	add_dialog_str(0,"As you pass the Pearl Bridge, you're pleased to see that the water level hasn't changed all that much. It looks like you actually managed to foil Joshua's plan and survive.",0);
	if(party_size() > 1)
		add_dialog_str(1,"When you reach Hektos, you are greeted by the ecstatic survivors. They can't exactly give you much of a reward, however, so you graciously decline the small sums they offer.",0);
	else
		add_dialog_str(1,"Sure enough, you are greeted by the people of Hektos as a hero. They can't exactly give you much of a reward, however, and you graciously decline the small sums they offer.",0);
	add_dialog_str(2,"When you reach Fort Galima, the guards give you a full salute, accented by rather rusty and out of tune trumpets. But the real prize is when Commander Ylissa congratulates you, with actual sincerity.",0);
	add_dialog_str(3,"She presents you with a beautiful longsword and a hefty pouch of money. Not the best reward, but pretty good considering what their armory looked like.",0);
	add_dialog_str(4,"Once the ceremony ends, you quietly slip out of the fort and hit the open road again, satisfied with the job you did. It's quiet out here again, which is a nice enough reward in itself.",0);
	run_dialog(1);
	reward_give(58);
	change_coins(1500);
	block_entry(1);
	end_scenario(1);

break;